<template>
  <el-dialog :visible.sync="show" width="500px">
    <el-descriptions size="small" border :column="1" :label-style="{ width: '100px' }">
      <el-descriptions-item label="分部分项">{{ info.checkTypeName }}</el-descriptions-item>
      <el-descriptions-item label="工序">{{ info.checkTableName }}</el-descriptions-item>
    </el-descriptions>
    <el-table :data="list" size="small" style="margin-top: 20px">
      <el-table-column width="50">
        <span slot-scope="{ row }" class="role-abbr">{{ row.abbr }}</span>
      </el-table-column>
      <el-table-column label="已验收" prop="showAcceptanceCount" align="center" />
      <el-table-column label="按比例应验" prop="showMeasure" align="center" />
      <el-table-column label="施工完成" prop="showInspectionCount" align="center" />
    </el-table>
  </el-dialog>
</template>
<script>
// 角色的进度比例展示
import { unitTypeList } from '@/utils/baseData'
import { roleList } from '../common'
const unitType2unit = unitTypeList.reduce((o, i) => !void (o[i.value] = i.unit) && o, {})
export default {
  data() {
    return {
      show: false,
      info: {},
      list: []
    }
  },
  methods: {
    open(data = {}) {
      this.show = true
      this.info = {
        checkTypeName: data.checkTypeName,
        checkTableName: data.checkTableName
      }
      const unit = unitType2unit[parseInt(data.unitType)] || ''
      const ratio = data.ratio || {}
      this.list = roleList.map(role => {
        const item = ratio[role.key] || {}
        const hasData = ratio[role.key] && item.measure !== 0
        item.showAcceptanceCount = hasData ? `${item.acceptanceCount} ${unit}` : '-'
        item.showMeasure = hasData ? `${item.measure} ${unit}` : '-'
        item.showInspectionCount = hasData ? `${item.inspectionCount} ${unit}` : '-'
        return { ...role, ...item }
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.role-abbr {
  display: inline-block;
  border-radius: 3px;
  background: #64aeec;
  color: white;
  font-size: 12px;
  line-height: 1;
  padding: 2px;
}
</style>
